
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>编辑产品</title>
    <link rel="stylesheet" href="styles/style.css" type="text/css" media="all">
</head>
<?php

session_start();
header("content-type:text/html;charset=utf-8");
include "Mysql/MySqlClass.php";
$mySQL   = new Ycf\Lession\MySqlClass\MySqlClass('jinling_company', 'root', '123456');
$product = $mySQL->select("product", $where = array('id' => $_GET['productId']));
$admin   = $mySQL->select("admin", $where = array('id' => $product['adminId']));

include "FileUpload/FileUpload.php";
$admin                  = $mySQL->select("admin", $where = array('adminName' => $_SESSION['userName']));
$companyInformationDate = date('y-m-d h:i:s', time()); //当前的编辑时间
if (isset($_POST['productName'])) {
    if (!isset($_POST['pic'])) {
        $up = new FileUpload;
//设置属性(上传的位置， 大小， 类型， 名是是否要随机生成)
        $up->set("path", "./images/");
        $up->set("maxsize", 2000000);
        $up->set("allowtype", array("gif", "png", "jpg", "jpeg"));
        $up->set("israndname", true);
        $up->upload("pic");
        $pictureName = $up->getFileName();
        $productDir  = "images/" . $pictureName;
    } else {
        $productDir = $product['productPictureDir'];
    }
    $productUpdate = array(
        'productName'       => $_POST['productName'],
        'productPictureDir' => $productDir,
        'productDescript'   => $_POST['productDescripe'],
        'adminId'           => $admin['id'],
        'productDate'       => $companyInformationDate,
        'productTypeId'  =>$_POST['productType'],
    );
    $mySQL->update("product", $productUpdate, $where = array('id' => $_GET['productId']));
    header("Location:productList.php");
}
?>
<body>
<div class="container">
    <h3 class="marginbot">编辑产品<a href="" class="sgbtn">返回产品列表</a></h3>
    <div class="mainbox">
        <form method="post" enctype="multipart/form-data" action="">
            <td>
                <input name="productName" class="txt"   value="<?php echo $product['productName']; ?>" style="width:400px;" type="text">
            </td>
            </tr>
            <tr>
                <th>产品描述：</th>
            </tr>
            <tr>
                <td><textarea style="width:400px; height:150px" name="productDescripe"><?php echo $product['productDescript']; ?></textarea></td>
            </tr>
            <tr>
                <th>产品类型：</th>
            </tr>
            <tr>
                <select name="productType">
                    <option value="1">类型1</option>
                    <option value="2">类型2</option>
                    <option value="3">类型3</option>
                    <option value="4">类型4</option>
                </select>
            </tr>
            <tr><td>上次编辑者：<?php echo $admin['adminName']; ?></td></tr>
            <tr><td>上次保存产品图片：<?php echo $product['productPictureDir']; ?></td></tr>
            <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
            <input type="file" name="pic" value="" multiple="multiple"><br>
            <input type="submit" value="提交" name="B1">
        </form>
    </div>
</div>
</body>
</html>
